/*
 * @Author: sikonggpw 1327325804@qq.com
 * @Date: 2023-02-20 14:22:38
 * @LastEditors: sikonggpw 1327325804@qq.com
 * @LastEditTime: 2023-02-22 14:34:41
 * @FilePath: \spider-node\server.js
 * @Description: 后台运行主程序
 */
const express = require('express')
const cors = require("cors");
const cheerio = require('cheerio');
const userController = require("./server");
const bodyParser = require('body-parser');
const port = 3000

const app = express()

app.use(cors());
app.use(bodyParser.json());


// async function useSpider(url) {
//     try {
//         return await fetch(url).then(result => result.text())
//     } catch (error) {

//     }
// }

// function useLoadLink(html, matched = 'a[href^="/hash/"]') {
//     const $ = cheerio.load(html);
//     const links = $(matched);

//     let resultArr = []
//     links.each((index, link) => {
//         resultArr.push($(link).attr('href'))
//     });
//     return resultArr
// }
// 注册路由
app.post("/register", userController.register);

// 登录路由
app.post("/login", userController.login);

app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
})
